package com.study.userserviceprovider.configuration;

import com.study.userserviceprovider.entry.TestClass;
import com.study.userserviceprovider.entry.TestClassCustomizer;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 此类描述的是：
 *
 * @author: 李军容
 * @version: 2020/11/15 9:16
 */
@Configuration
public class TestConfiguration {

    public static void main(String[] args) {
        TestConfiguration testconfiguration = new TestConfiguration();
        TestClassCustomizer testClassCustomizer = testconfiguration.testClassCustomizer();
        testClassCustomizer.customize(new TestClass());
    }


    @Qualifier
    @Bean(name = "testClass1")
    public TestClass testClass1(){
        return new TestClass();
    }

    @Qualifier
    @Bean(name = "testClass2")
    public TestClass testClass2(){
        return new TestClass();
    }


    @Bean
    @ConditionalOnMissingBean
    public TestClassCustomizer testClassCustomizer() {
        TestClassCustomizer testClassCustomizer = new TestClassCustomizer() {
            @Override
            public void customize(TestClass testClass) {
                testClass.setName("1111");
            }
        };

        //return testClassCustomizer;
        return (testClass)->{
            testClass.setName("1111");
            System.out.println(testClass);
        };
    }

}
